home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibRadioBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  4.5 KB  |  197 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display    *dpy;
  5. extern GC     mib_gc;
  6.  
  7. /* Code for RadioBox */
  8. /*****************************************************************************/
  9.  
  10. mib_Widget *mib_create_RadioBox(mib_Widget *parent, char *name, char *label,
  11.         int posx, int posy, int width, int height, int mib_fill)
  12. {
  13.   mib_Widget    *temp;
  14.   mib_RadioBox  *myres;
  15.   Widget    wtemp;
  16.   unsigned char *label_text;
  17.   char        label_temp[50];
  18.   Arg        args[20];
  19.   int        n;
  20.  
  21.   /* create the new widget and add it to the tree */
  22.  
  23.   temp = mib_new_mib_Widget();
  24.   if (mib_fill == WDEFAULT)
  25.     mib_add_backward(temp, parent);
  26.   else
  27.     mib_add_mib_Widget(temp, parent);
  28.  
  29.   myres = (mib_RadioBox *)malloc(sizeof(mib_RadioBox));
  30.  
  31.   /* initialize public resources */
  32.  
  33.   if (mib_fill == WDEFAULT)
  34.   {
  35.     temp->name = (char *)malloc(strlen(name)+1);
  36.     strcpy(temp->name,name);
  37.   }
  38.   temp->mib_class = (char *)malloc(9);
  39.   sprintf(temp->mib_class,"RadioBox");
  40.   temp->mib_class_num = MIB_RADIOBOX;
  41.  
  42.   temp->width = width;
  43.   temp->height = height;
  44.   temp->topOffset = posy;
  45.   temp->leftOffset = posx;
  46.   temp->bottomOffset = 0;
  47.   temp->rightOffset = 0;
  48.   temp->topAttachment = 1;
  49.   temp->leftAttachment = 1;
  50.   temp->bottomAttachment = 0;
  51.   temp->rightAttachment = 0;
  52.  
  53.   temp->mib_allowresize = 0;
  54.  
  55.   /* initialize private resources */
  56.  
  57.   temp->myres = (void *)myres;
  58.  
  59.   myres->numlabel = 0;
  60.  
  61.   if (mib_fill == WDEFAULT)
  62.   {
  63.     myres->numlabel = 2;
  64.     myres->labels = (char **)malloc(10);
  65.     myres->buttons = (Widget *)malloc(sizeof(Widget) * myres->numlabel);
  66.     sprintf(label_temp, "Radio 1");
  67.     myres->labels[0] = (char *)malloc(strlen(label_temp)+1);
  68.     strcpy(myres->labels[0],label_temp);
  69.     sprintf(label_temp, "Radio 2");
  70.     myres->labels[1] = (char *)malloc(strlen(label_temp)+1);
  71.     strcpy(myres->labels[1],label_temp);
  72.   }
  73.  
  74.  
  75.   /* create Xt widget */
  76.  
  77.   n = 0;
  78.  
  79.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  80.  
  81.   if (mib_fill == WDEFAULT)
  82.   {
  83.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  84.     XtSetArg (args[n], XmNleftOffset, posx);n++;
  85.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  86.     XtSetArg (args[n], XmNtopOffset, posy);n++;
  87.     XtSetArg (args[n], XmNwidth, width); n++;
  88.     XtSetArg (args[n], XmNheight, height); n++;
  89.   }
  90.  
  91.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  92.  
  93.   temp->me = XmCreateRadioBox(temp->parent->me, "Radio", args, n);
  94.   wtemp = temp->me;
  95.  
  96.  
  97.   if (mib_fill == WDEFAULT)
  98.   {
  99.     n = 0;
  100.     XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  101.  
  102.     XtCreateManagedWidget("Radio 1", xmToggleButtonGadgetClass,
  103.         wtemp, args, n);
  104.  
  105.     n = 0;
  106.     XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  107.     XtCreateManagedWidget("Radio 2", xmToggleButtonGadgetClass,
  108.         wtemp, args, n);
  109.   }
  110.  
  111.  
  112.   XtManageChild(wtemp);
  113.  
  114.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  115.   {
  116.     mib_apply_eventhandlers(temp->me, temp);
  117.   }
  118.  
  119.   return temp;
  120. }
  121.  
  122. void mib_delete_RadioBox(mib_Widget *this)
  123. {
  124.   mib_RadioBox *temp = (mib_RadioBox *)this->myres;
  125.   int        count;
  126.  
  127.   for (count=0; count < temp->numlabel; count++)
  128.     free(temp->labels[count]);
  129.  
  130.   free(temp);
  131. }
  132.  
  133. void mib_save_RadioBox(mib_Widget *this, FILE *fout)
  134. {
  135.   mib_RadioBox *temp = (mib_RadioBox *)this->myres;
  136.   int count;
  137.  
  138.   fprintf(fout,"numlabel: %d\\n\\\n", temp->numlabel);
  139.  
  140.   for (count=0; count < temp->numlabel; count++)
  141.   {
  142.     fprintf(fout,"label: \\\"%s\\\"\\n\\\n", temp->labels[count]);
  143.   }
  144. }
  145.  
  146. int mib_load_RadioBox(mib_Widget *this, mib_Buffer *fin)
  147. {
  148.   char        res[MI_MAXSTRLEN];
  149.   char        val[MI_MAXSTRLEN];
  150.   int        count, vallen, n;
  151.   Arg        args[5];
  152.   mib_RadioBox *myres;
  153.  
  154.   myres = (mib_RadioBox *)this->myres;
  155.  
  156.   if (!mib_read_line(fin, res, val))
  157.     return 0;
  158.  
  159.   if (!strcmp(res,"numlabel"))
  160.   {
  161.     myres->numlabel = 0;
  162.     sscanf(val,"%d",&(myres->numlabel));
  163.     if (!(myres->numlabel))
  164.       return 0;
  165.  
  166.     myres->labels = (char **)malloc((myres->numlabel+1)*4);
  167.     myres->buttons = (Widget *)malloc(sizeof(Widget)*(myres->numlabel));
  168.     for (count=0; count < myres->numlabel; count++)
  169.     {
  170.       if (!mib_read_line(fin, res, val))
  171.     return 0;
  172.       vallen = strlen(val);
  173.       if (vallen < 2)
  174.     return 0;
  175.       val[vallen-1] = '\0';
  176.       myres->labels[count] = (char *)malloc(vallen-1);
  177.       sprintf(myres->labels[count],"%s",&(val[1]));
  178.  
  179.       n = 0;
  180.       XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  181.  
  182.       myres->buttons[count] = XtCreateManagedWidget(myres->labels[count],
  183.         xmToggleButtonGadgetClass, this->me, args, n);
  184.  
  185.     }
  186.   }
  187.   else
  188.     return 0;
  189.  
  190.   if (!mib_read_line(fin, res, val))
  191.     return 0;
  192.   if (strcmp(res,"EndWidget"))
  193.     return 0;
  194.  
  195.   return 1;
  196. }
  197.